﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

public partial class Admin_Article_ArticleCategoryAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
            BindData();
    }
    protected void BindData()
    {
        sort.Text = "0";

        MatchIns.BLL.TArticleCategory bll = new MatchIns.BLL.TArticleCategory();
        List<MatchIns.Model.TArticleCategory> ds = new List<MatchIns.Model.TArticleCategory>();
        bll.GetList(0, bll.GetList(), ds, "");

        parentId.Items.Clear();
        parentId.DataSource = ds;
        parentId.DataTextField = "CategoryName";
        parentId.DataValueField = "ArticleCategoryId";
        parentId.DataBind();
        parentId.Items.Insert(0,new ListItem("请选择..."));
    }

    protected void save_Click(object sender, EventArgs e)
    {
        #region 赋值
        MatchIns.Model.TArticleCategory model = new MatchIns.Model.TArticleCategory();
        model.CategoryName = categoryName.Text.Trim();
        int _parentid;
        double _sort;
        int.TryParse(parentId.SelectedValue, out _parentid);
        model.ParentId = _parentid;
        double.TryParse(sort.Text, out _sort);
        model.Sort = _sort;
        #endregion

        #region 验证
        errors.Items.Clear();

        if (model.CategoryName.Length == 0)
            errors.Items.Add("填写分类名称");

        if (errors.Items.Count > 0)
            return;

        #endregion


        #region 添加至数据库
        new MatchIns.BLL.TArticleCategory().Add(model);
        errors.Items.Add("分类添加成功");
        #endregion

        #region 初始化控件
        categoryName.Text = "";
        BindData();
        #endregion

    }
    protected void cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("ArticleCategoyList.aspx");
    }
}
